CROSS_COMPILE ?=arm-linux-gnueabihf-
CC  = $(CROSS_COMPILE)gcc
CPP = $(CROSS_COMPILE)g++
AR  = $(CROSS_COMPILE)ar

ENABLE_HDMI = 0
ENABLE_HDMI_USE_EXTRA_LIB = 0

ifeq ($(ENABLE_HDMI), 1)
CODEDEFINE = -DCONFIG_DEMO_ENABLE_HDMI
else
CODEDEFINE = 
endif

ifeq ($(ENABLE_HDMI_USE_EXTRA_LIB), 1)
CODEDEFINE += -DCONFIG_DEMO_ENABLE_HDMI_USE_EXTRA_LIB
else
CODEDEFINE += 
endif

COM_FLAGS = -Wall -O2 -fPIC -mcpu=cortex-a9 -mfpu=neon-fp16 -mfloat-abi=hard -mthumb-interwork -marm
C_FLAGS	   = $(COM_FLAGS) -std=gnu11 $(CODEDEFINE)
CPP_FLAGS  = $(COM_FLAGS) -std=gnu++11 $(CODEDEFINE)


ifeq ($(ENABLE_HDMI_USE_EXTRA_LIB), 1)
INCLUDES  += -I. -I../../../project/release/include/ -I./host/include/ -I../../common/edidparser/include/
else
INCLUDES  += -I. -I../../../project/release/include/ -I./host/include/
endif

TARGET_NAME  = SsPlayer

CPP_SRCS  =  

ifeq ($(ENABLE_HDMI_USE_EXTRA_LIB), 1)
C_SRCS = main.c SsPlayer.c sstardisp.c ../../common/edidparser/parse-edid.c
else
C_SRCS = main.c SsPlayer.c sstardisp.c
endif
			
CPP_OBJS = $(patsubst %.cpp, %.cpp.o, $(CPP_SRCS))
C_OBJS = $(patsubst %.c, %.c.o, $(C_SRCS))

LIB_PATH  = -L. -L../../../project/release/nvr/i2m/common/glibc/8.2.1/mi_libs/dynamic -L./host/lib
ifeq ($(ENABLE_HDMI), 1)
LIB_NAME += -lavformat -lavcodec -lavutil -lswresample -pthread -lm -lmi_vdec -lmi_sys -lmi_divp -lmi_disp -lmi_ao -lmi_common -ldl -lmi_panel -lmi_hdmi
else
LIB_NAME += -lavformat -lavcodec -lavutil -lswresample -pthread -lm -lmi_vdec -lmi_sys -lmi_divp -lmi_disp -lmi_ao -lmi_common -ldl -lmi_panel
endif

.PHONY: all prepare clean

all: prepare $(TARGET_NAME) finish

prepare:
	@echo
	@echo ">>>>========================================================"
	@echo "TARGET_NAME = $(TARGET_NAME)"
	@echo "C_FLAGS = $(C_FLAGS)"
	@echo "CPP_FLAGS = $(CPP_FLAGS)"
	@echo

clean:
	@rm -Rf $(CPP_OBJS)
	@rm -f $(C_OBJS)
	@rm -Rf $(TARGET_NAME)

finish:
	@echo "make done"
	@echo "<<<<========================================================"
	@echo

$(TARGET_NAME): $(CPP_OBJS) $(CPP_SRCS) $(C_OBJS) $(C_SRCS)
	@echo "generate $@"
	@$(CC) -o $@ $(C_OBJS) $(CPP_OBJS) $(LIB_PATH) $(LIB_NAME) -lm -lpthread

%.c.o : %.c
	@echo "compile $@"
	@$(CC) $(C_FLAGS) $(INCLUDES) $(DEFINES) -c $< -o $@

%.cpp.o : %.cpp
	@echo "compile $@"
	@$(CPP) $(CPP_FLAGS) $(INCLUDES) $(DEFINES) -c $< -o $@
